#include <iostream>
#include <vector>
#include <string>

using namespace std;

const string l = "({[", r = ")}]";

bool isValid(string s)
{
    vector<char> stk;
    for (size_t i = 0; i < s.size(); i++)
    {
        if (r.find(s[i]) != -1)
        {
            if (stk.empty() || stk.back() != l[r.find(s[i])])
            {
                return false;
            }
            else
            {
                stk.pop_back();
            }
        }
        else
        {
            stk.push_back(s[i]);
        }
    }
    return stk.empty() ? true : false;
}

int main()
{
    string s = "([]{})";
    cout << isValid(s) << endl;
    return 0;
}
